package com.jboltai.event.ai.aitext.text2sql;

import cn.hutool.core.util.StrUtil;
import com.jboltai.event.CompleteHandler;
import com.jboltai.event.EventType;
import com.jboltai.event.FailHandler;
import com.jboltai.event.SuccessHandler;
import com.jboltai.event.ai.aitext.AITextEvent;
import com.jboltai.event.handler.Text2SqlEventHandler;
import com.jboltai.resource.ai.AIModel;

public class Text2SqlEvent extends AITextEvent<Text2SqlEvent, String, Text2SqlEventHandler>  {
    public Text2SqlEvent() {
        super(EventType.AI_TEXT_TO_SQL);

    }

    public Text2SqlEvent(AIModel model) {
        super(EventType.AI_TEXT_TO_SQL);
        this.aiChatEvent.setModel(model);
    }


    /**
     * 创建一个ai事件
     * @param model 使用哪个模型，具体的模型名称根据该枚举值的defaultModel获取
     * @param successHandler
     * @param failHandler
     */
    public Text2SqlEvent(AIModel model, SuccessHandler<Text2SqlEvent, String> successHandler, FailHandler failHandler) {
        super(EventType.AI_TEXT_TO_SQL);
        this.aiChatEvent.setModel(model);
        this.successHandler = successHandler;
        this.failHandler = failHandler;
    }
    /**
     * 创建一个ai事件
     * @param model 使用哪个模型，具体的模型名称根据该枚举值的defaultModel获取
     * @param successHandler
     * @param failHandler
     */
    public Text2SqlEvent(AIModel model, SuccessHandler<Text2SqlEvent, String> successHandler, FailHandler failHandler, CompleteHandler completeHandler) {
        super(EventType.AI_TEXT_TO_SQL);
        this.aiChatEvent.setModel(model);
        this.successHandler = successHandler;
        this.failHandler = failHandler;
        this.completeHandler = completeHandler;
    }

    /**
     * 数据库类型
     */
    private DBType dbType = DBType.mysql;

    /**
     * 背景知识
     */
    private String background = null;

    /**
     * 限制生成的sql类型
     */
    private SqlType[] limitSqlType = null;






    public DBType getDBType() {
        return dbType;
    }

    public Text2SqlEvent dbType(DBType dbType) {
        this.dbType = dbType;
        return this;
    }

    public String getBackground() {
        return background;
    }

    public Text2SqlEvent background(String background) {
        this.background = background;
        return this;
    }

    public SqlType[] getLimitSqlType() {
        return limitSqlType;
    }

    public Text2SqlEvent limitSqlType(SqlType... limitSqlType) {
        this.limitSqlType = limitSqlType;
        return this;
    }



    @Override
    public String preCheck() {
        if (StrUtil.isBlank(this.oriPrompt) ) {
            return "未设置用户消息";
        }
        if (dbType == null) {
            return "未设置数据库类型";
        }
        if (StrUtil.isBlank(background)) {
            return "未设置背景知识";
        }
        return null;
    }



}
